import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import employees from '@/router/modules/employees'
import settings from '@/router/modules/settings'
import permissions from '@/router/modules/permissions'
import social_securitys from '@/router/modules/social_securitys'
import approvals from '@/router/modules/approvals'
import attendances from '@/router/modules/attendances'
import salarys from '@/router/modules/salarys'
import departments from '@/router/modules/departments'

export const asyncRoutes = [
  departments,
  settings,
  employees,
  permissions,
  social_securitys,
  approvals,
  attendances,
  salarys
]

export const constantRoutes = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName:"login"*/'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }

]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重新设置路由的可匹配路径
}

export default router
